#!/usr/bin/env python
# encoding: utf-8
'''
Created on Jun 6, 2011

@author: apple
'''
import redis
import pymongo


from flask import Flask,g
from flask.signals import Namespace
from flaskext.cache import Cache

app = Flask(__name__)
app.config.from_object('config.DevelopmentConfig')
cache = Cache(app)

signals = Namespace() 
app.signal_addquestion = signals.signal('addquestion')
app.signal_addanswer   = signals.signal('addanswer')
app.signal_getquestion = signals.signal('getquestion')
app.signal_indexobject = signals.signal('indexobject')
app.signal_addtagscore = signals.signal('addtagscore')
app.signal_tagquestions= signals.signal('tagquestions')
app.signal_gettopcatalog = signals.signal('gettopcatalog')

@app.before_request
def before_request():
    pass

@app.after_request
def after_request(response):
    if getattr(g, 'mongo',None):
        g.mongo.disconnect()
    if getattr(g, 'redis' , None):
        #config redis.conf timeout auto disconnect
        pass
#        g.redis.connection.disconnect()
    if getattr(g , 'memcache' , None):
        g.memcache.disconnect_all()
    return response

from apps.user.views import user
from apps.question.views import question
from apps.tag.views import tag
from apps.catalog.views import catalog

app.register_module(question)
app.register_module(user, url_prefix='/u')
app.register_module(tag, url_prefix='/t')
app.register_module(catalog,url_prefix='/c')

